<template>
  <div>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm"  label-position="top" label-width="80px" class="demo-ruleForm" size="large" >

      <el-form-item label="ProductID"  >
        <el-input v-model="ruleForm.productId" readonly style="width:300px"></el-input>
      </el-form-item>
      <el-form-item label="Category" prop="categoryId">
        <el-input v-model="ruleForm.categoryId"style="width:300px"></el-input>
      </el-form-item>
      <el-form-item label="Name" prop="name">
        <el-input v-model="ruleForm.name"style="width:300px"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">修改</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>

</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        productId: this.$route.query.productId,
        categoryId: this.$route.query.categoryId,
        name: this.$route.query.name,
      },
      rules: {
        categoryId: [
          {required: true, message: '请输入正确的内容', trigger: 'blur'},
        ],
        name: [
          {required: true, message: '请输入正确的内容', trigger: 'blur'},
        ],


      }
    };
  },
  methods: {
    submitForm(formName) {
      const _this = this;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          axios({
            method: "PUT",
            url: 'http://115.29.176.82:8081/manager/api/product',
            data: {
              productId: _this.ruleForm.productId,
              categoryId: _this.ruleForm.categoryId,
              name: _this.ruleForm.name,
              description:''
            }
          }).then(function (resp) {
            console.log(resp)
            if (resp.status = 403)
              alert('修改成功，请继续您的操作')
          })
        } else {
          alert('ERROR！请修改您的数据后再次提交')
          return false;
        }
      });
    },


  }
}
</script>